$j.fn.extend({
	loading2:function(){
		return this.each(function(){
			$j(this).html('<div class="loading_box"><div class="progress_bar"><img src="'+__ctxPath+'/images/icon/loadingBig.gif"/>loading...</div></div>');			
		});
	}
});

//检查文件名
function checkFileName(importFile){
	importFile=importFile.substring(0,importFile.lastIndexOf("."));
	if(importFile.lastIndexOf(" ")==importFile.length-1){
		alert(__FMT.import_upload_file_error);
		return false;
	}else{
		return true;
	}
}
//下载文件
function downloadFile(fileUrl){
	fnAddHiddenField("doAction","downloadFile",$('importForm'));
	fnAddHiddenField("fileUrl",fileUrl,$('importForm'));
	$('importForm').submit();
}
//预览文件
var hasInit = false;
function preview(){
	if($('importFile').value == ""){
		alert(__FMT.import_upload_file_notEmpty);
		return;
	}
	var postData = $j('#importForm').serializeArray();
	var url = $('importForm').action + '?doAction=preview&decorator=blank&'+Math.floor(Math.random()*100000);
	$j('#previewDiv').empty().loading2().load(url,postData);
	if(hasInit){
		ui_dialog_previewDialog.dialog("open");
	}else{
		dlgpreviewDialog_show();
		hasInit =true;
	}	
	
}
//上传文件callback
function uploadFileCallback(mediaUrl,fileInputId){
	var fileName = mediaUrl.substring(mediaUrl.lastIndexOf("/")+1);
	$j('#fileNameDiv').html(fileName);
	
	countFileRowSize();
}

//获取上传文件长度
function countFileRowSize(){
	var postData = $j('#importForm').serializeArray();
	var url = $('importForm').action + '?doAction=countFileRowSize&decorator=blank&'+Math.floor(Math.random()*100000);
	$j('#fileRowSize').loading2();
	$j.post(url,postData,countFileRowSizeCallback,"json");
}
//获取上传文件长度 callback
function countFileRowSizeCallback(data){
	$j('#fileRowSize').html(__FMT.import_fileRowSize_tip_1+"<b>&nbsp;"+data.rowCount+"&nbsp;</b>"+__FMT.import_fileRowSize_tip_2);
}


//开始导入
function startImport(){
	if($('importFile').value == ""){
		alert(__FMT.import_upload_file_notEmpty);
		return;
	}
	fnAddHiddenField("doAction","startImport",$('importForm'));
	$('importForm').submit();
}
